<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon
      :icon-class="isFullscreen? 'exit-fullscreen' : 'fullscreen'"
      class="fullscreen"
      @click="toggleScreen"
    />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullscreen: false // 全屏
    }
  },
  mounted() {
  // 监听全屏的状态是否切换
    screenfull.on('change', () => {
      console.log(screenfull)
      this.isFullscreen = screenfull.isFullscreen
    })
  },
  methods: {
    // 点击全屏切换
    toggleScreen() {
      screenfull.toggle()
      // this.isFullscreen = !this.isFullscreen
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
